<div class="tmd-doc">
﻿<h1>Go 101</h1>

<p>
<i>Go 101</i> is a book focusing on Go syntax/semantics
(except <a href="../generics/101.html">custom generics</a> related) and
all kinds of runtime related things.
It tries to help gophers gain a deep and thorough understanding of Go.
This book also collects many details of Go and in Go programming.
Many of these details could not be found in official Go documentations.
It is expected that this book is helpful for both beginner and experienced Go programmers.
</p>

<p>
The book is Go 1.25 ready now (<a href="100-updates.html">update history</a>).
</p>

<p><small><i>
(Please follow Go 101's official Twitter account <a href="https://twitter.com/zigo_101">@zigo_101</a>
to get latest Go 101 news and learn all kinds of Go knowledge.)
</i></small></p>

<div class="alert alert-success row item-row">
	<div class="col-xs-12 col-sm-3 text-center" style="font-size: small;">
		<img src="res/cover-1000x.jpg" style="width: 160px;" alt="Go 101"></img>
		<p>(about 500 pages, 350+ examples, 101+ details)</p>
	</div>
	<div class="col-xs-12 col-sm-9" style="padding-top: 6px;"><small>
		
		The book is free to <a href="#index">read online</a>.
		Ebooks are also available as a way to support Go 101:

		<ul>
		<li>
			<a href="https://leanpub.com/go101">Leanpub store</a>,
			<i>$19.99+ (You can get this book from <a href="https://leanpub.com/b/go-optimizations-details-generics-fundamentals">this boundle</a> which also contains 3 other books, with the same price)</i>.
		</li>
		<!--li>
			<a href="https://www.amazon.com/dp/B07Q3HWZ98">Amazon Kindle store</a>,
			<i>$39.99</i>.
		</li-->
		<li>
			<a href="https://books.apple.com/book/id1459984231">Apple Books store</a>,
			<i>$19.99</i>.
		</li>
		<li>
			<a href="https://play.google.com/store/books/details?id=Dc1wEAAAQBAJ">Google Play store</a>,
			<i>$19.99</i>.
		</li>
		</ul>
		
		<p>
		Ebooks are also freely available <a href="https://github.com/go101/go101/releases">here</a>.
		</p>

		<p>
		Tapir, the author of Go 101, has been on writing the Go 101 series books and maintaining the go101.org website since July 2016.
		New contents are still being (and will be) constantly added to the book series and the website from time to time.
		</p>

		<p>
		Tapir is also an indie game developer.
		If you would like to, you can also support the book and the website by
		playing <a href="https://www.tapirgames.com">Tapir's games</a>
		(made for both Android and iPhone/iPad).
		Individual donations are also accepted <a href="https://paypal.me/tapirliu">via PayPal</a>.
		</p>

		<p>
		Thanks to
		<a href="http://reneefrench.blogspot.com">Renee French</a> and Rob Pike
		for the permission of using the image from
		<a href="https://talks.golang.org/2012/waza.slide#19">the slide</a>
		in the book cover.
		</p>
	</small></div>
</div>

<!--
<div class="alert alert-danger"><small>
	<i>2022/Sep/02</i>: I'm sorry for the last Erratum, which still doesn't explain panic/recover mechanism well.
	Please read <a href="panic-and-recover-more.html">the latest version</a> instead.
</small></div>

<div class="alert alert-danger"><small>
	<s><i>2022/Aug/16</i>: the article <a href="panic-and-recover-more-newer.html">Explain Panic/Recover Mechanism in Detail</a>
	is updated to be consistent with the official standard Go runtime.
	Please read the starting note in <a href="panic-and-recover-more-old.html">the old version of this article</a> for the change.</s>
</small></div>

<div class="alert alert-danger"><small>
	<i>2021/Apr/11</i>: The implementation of the <code>(*Counter).xAddr</code> method in the
	<a href="memory-layout.html">memory layout</a> article was wrong.
	This mistake <a href="https://github.com/go101/go101/commit/d4c9bd303417ad730466cc8f65831243aeac5dc2">has been fixed</a> now.
</small></div>

<div class="alert alert-danger"><small>
	<i>2020/Sep/06</i>: This book ever mentioned that using "append" to clone slices is often
	<a href="https://github.com/go101/go101/wiki/How-to-efficiently-clone-a-slice%3F">much more efficient than</a>
	using "make+copy" to clone slices. This is valid for Go Toolchain before version 1.15.
	However, since version 1.15, the official standard Go compiler has made special optimizations for
	the latter way, so now the latter way is always more efficient than the former way (the "append" way).
</small></div>

<div class="alert alert-danger"><small>
	<i>2020/Aug/13</i>: Correction: the <a href="string.html#conversion-optimizations">Compiler Optimizations for Conversions Between Strings and Byte Slices</a>
	section said "a conversion (from byte slice to string) which is used as a map key in map element indexing syntax" before. In fact, it shoud be
	"a conversion (from byte slice to string) which is used as a map key in map element <b>retrieval</b> indexing syntax". The example code is also corrected.
</small></div>

<div class="alert alert-warning"><small>
	<i>2020/Jun/02</i>: All "Go SDK" uses are changed to "Go Toolchain".
</small></div>


<div class="alert alert-warning"><small>
	<i>2020/Apr/22</i>: <code>runtime.KeepAlive</code> calls are helpless in making some invalid <code>unsafe.Pointer</code> uses become valid.
	Some places in the <a href="unsafe.html">Type-Unsafe Pointers</a> article are adjusted for this. Please re-read this article for details.
	<i>(I apologize for spreading the wrong information before in this article.)</i>
</small></div>

<div class="alert alert-warning"><small>
	<i>2019/Oct/30</i>: 
	<ul>
	<li>
	<a href="https://github.com/go101/go101/commit/35b8f5e2aa7440c25bf0a784b5bde506d4ec3a65#diff-8eb02937949dd308587a57ed66732712">fixed a bug</a> in the "deleting subslice" example.
	</li>
	<li>
	<a href="https://github.com/go101/go101/commit/8b62837d3c957f45664679a622872d292806f76a#diff-e68191d52283c7638734b55744e083cf">corrected the explanation</a> for "The Evaluation Moment of Deferred Function Values".
	</li>
	<li>
	The article "The Right Places to Call the Built-in <code>recover</code> Function" is renamed to <a href="panic-and-recover-more.html">Explain Panic/Recover Mechanism in Detail</a>. It is almost wholly re-written.
	</li>
	</ul>
	
</small></div>

<div class="alert alert-warning"><small>
	<i>2019/Oct/18</i>: <a href="https://github.com/golang/go/issues/27821#issuecomment-543611217">An explanation description flaw</a> is found in the
	<a href="evaluation-orders.html#value-assignment">Evaluation and Assignment Orders in Assignment Statements</a> section
	in the "Expression Evaluation Orders" article.
	A simpler description is provided now.
</small></div>

<div class="alert alert-warning"><small>
	<i>2019/Sep/30</i>: <a href="unsafe.html#fact-value-address-might-change">A new fact</a> is added to the "Type-Unsafe Pointers" article
	<strike>and a serious mistake was found in the
	<a href="unsafe.html#pattern-convert-to-uintptr-and-back">pattern 3: convert unsafe pointer to uintptr,
	do arithmetic operations with the uintptr value, then convert it back</a> section</strike>.
	(<i>I decided to withdraw this erratum.</i>)
</small></div>

<div class="alert alert-warning"><small>
	<i>2019/Sep/25</i>: The book made <a href="panic-and-recover-more.html#recover-order">a stupid mistake</a>
	in the "The Right Places to Call the recover Function" article. The section containing the mistake will be modified after some time.
</small></div>

<div class="alert alert-warning"><small>
	<i>2019/Sep/19</i>: The "named type" and "unnamed type" terminologies are added back in this book.
	But they are equivalent to "defined type" and "non-defined type" now.
</small></div>

<div class="alert alert-warning"><small>
	<i>2019/Apr/09</i>: This book removed the "alias type", "named type" and "unnamed type" terminologies.
	"Type alias" is still used.
</small></div>

<div class="alert alert-warning"><small>
	<i>2018/Dec/27</i>: A serious mistake was just fixed in this book.
	Before, the book said the starting index in a subslice syntax
	can't be larger than the length of the base slice.
	This is wrong. This restriction never exists.
	Please read <a href="container.html#subslice">the corrected section</a> again for details.
</small></div>

<div class="alert alert-warning"><small>
	<i>2019/Jan/15</i>: The example for <a href="channel-use-cases.html#rate-limiting">rate-limit</a>
	was not correctly implemented before. Now it is fixed.
</small></div>
-->

<div>

<h3 id="index">Index:</h3>

<!-- index starts (don't remove) -->

<div id="book-index">

<!-- kindle starts: 1 -->

<ul class="index part">
	<li><a class="index" href="101-about.html">About Go 101</a> - why this book is written.</li>
	<li><a class="index" href="acknowledgements.html">Acknowledgments</a></li>
</ul>

<ul class="index part">
	<li><a class="index" href="introduction.html">An Introduction of Go</a> - why Go is worth learning.</li>
	<li><a class="index" href="go-toolchain.html">The Go Toolchain</a> - how to compile and run Go programs.</li>
</ul>

<ul class="index part">
<li>
Become Familiar With Go Code

	<ul class="index chapters">
	<li><a class="index" href="basic-code-elements-introduction.html">Introduction of Source Code Elements</a></li>
	<li><a class="index" href="keywords-and-identifiers.html">Keywords and Identifiers</a></li>
	<li><a class="index" href="basic-types-and-value-literals.html">Basic Types and Their Value Literals</a></li>
	<li><a class="index" href="constants-and-variables.html">Constants and Variables</a> - also introduces untyped values and type deductions.</li>
	<li><a class="index" href="operators.html">Common Operators</a> - also introduces more type deduction rules.</li>
	<li><a class="index" href="function-declarations-and-calls.html">Function Declarations and Calls</a></li>
	<li><a class="index" href="packages-and-imports.html">Code Packages and Package Imports</a></li>
	<li><a class="index" href="expressions-and-statements.html">Expressions, Statements and Simple Statements</a></li>
	<li><a class="index" href="control-flows.html">Basic Control Flows</a></li>
	<li><a class="index" href="control-flows-more.html">Goroutines, Deferred Function Calls and Panic/Recover</a></li>
	</ul>

</li>
</ul>

<ul class="index part">
<li>
Go Type System

	<ul class="index chapters">
	<li><a class="index" href="type-system-overview.html">Go Type System Overview</a> - a must read to master Go programming.</li>
	<li><a class="index" href="pointer.html">Pointers</a></li>
	<li><a class="index" href="struct.html">Structs</a></li>
	<li><a class="index" href="value-part.html">Value Parts</a> - to gain a deeper understanding into Go values.</li>
	<li><a class="index" href="container.html">Arrays, Slices and Maps</a> - first-class citizen container types.</li>
	<li><a class="index" href="string.html">Strings</a></li>
	<li><a class="index" href="function.html">Functions</a> - function types and values, including variadic functions.</li>
	<li><a class="index" href="channel.html">Channels</a> - the Go way to do concurrency synchronizations.</li>
	<li><a class="index" href="method.html">Methods</a></li>
	<li><a class="index" href="interface.html">Interfaces</a> - value boxes used to do reflection and polymorphism.</li>
	<li><a class="index" href="type-embedding.html">Type Embedding</a> - type extension in the Go way.</li>
	<li><a class="index" href="unsafe.html">Type-Unsafe Pointers</a></li>
	<li><a class="index" href="generic.html">Generics</a> - use and read composite types</li>
	<li><a class="index" href="reflection.html">Reflections</a> - the <code>reflect</code> standard package.</li>
	</ul>
</li>
</ul>

<!-- kindle ends: 1 -->

<!-- kindle starts: 2 -->

<ul class="index part">
<li>
Some Special Topics

	<ul class="index chapters">
	<li><a class="index" href="line-break-rules.html">Line Break Rules</a></li>
	<li><a class="index" href="defer-more.html">More About Deferred Function Calls</a></li>
	<li><a class="index" href="panic-and-recover-use-cases.html">Some Panic/Recover Use Cases</a></li>
	<li><a class="index" href="panic-and-recover-more.html">Explain Panic/Recover Mechanism in Detail</a> - also explains exiting phases of function calls.</li>
	<li><a class="index" href="blocks-and-scopes.html">Code Blocks and Identifier Scopes</a></li>
	<li><a class="index" href="evaluation-orders.html">Expression Evaluation Orders</a></li>
	<li><a class="index" href="value-copy-cost.html">Value Copy Costs in Go</a></li>
	<!-- (to remove) moved--> <li><a class="index" href="bounds-check-elimination.html">Bounds Check Elimination</a></li>
	</ul>

</li>
</ul>

<ul class="index part">
<li>
Concurrent Programming

	<ul class="index chapters">
	<li><a class="index" href="concurrent-synchronization-overview.html">Concurrency Synchronization Overview</a></li>
	<li><a class="index" href="channel-use-cases.html">Channel Use Cases</a></li>
	<li><a class="index" href="channel-closing.html">How to Gracefully Close Channels</a></li>
	<li><a class="index" href="concurrent-synchronization-more.html">Other Concurrency Synchronization Techniques</a> - the <code>sync</code> standard package.</li>
	<li><a class="index" href="concurrent-atomic-operation.html">Atomic Operations</a> - the <code>sync/atomic</code> standard package.</li>
	<li><a class="index" href="memory-model.html">Memory Order Guarantees in Go</a></li>
	<li><a class="index" href="concurrent-common-mistakes.html">Common Concurrent Programming Mistakes</a></li>
	</ul>

</li>
</ul>


<ul class="index part">
<li>
Memory Related

	<ul class="index chapters">
	<li><a class="index" href="memory-block.html">Memory Blocks</a></li>
	<li><a class="index" href="memory-layout.html">Memory Layouts</a></li>
	<li><a class="index" href="memory-leaking.html">Memory Leaking Scenarios</a></li>
	</ul>

</li>
</ul>

<ul class="index part">
<li>
Some Summaries

	<ul class="index chapters">
	<li><a class="index" href="summaries.html">Some Simple Summaries</a></li>
	<li><a class="index" href="nil.html"><code>nil</code> in Go</a></li>
	<li><a class="index" href="value-conversions-assignments-and-comparisons.html">Value Conversion, Assignment and Comparison Rules</a></li>
	<li><a class="index" href="exceptions.html">Syntax/Semantics Exceptions</a></li>
	<!-- (to remove) for printing
	<li><a class="index" href="details.html">Go Details 101</a></li>
	(to remove) -->
	<li><a class="index" href="unofficial-faq.html">Go FAQ 101</a></li>
	<!-- (to remove) for printing
	<li><a class="index" href="tips.html">Go Tips 101</a></li>
	(to remove) -->
	</ul>

</li>
</ul>

<!-- kindle ends: 2 -->

<!-- kindle starts: 0 -->

<ul class="index part">
<li><a class="index" href="more.html">More Go Related Topics</a></li>
</ul>

<!-- kindle ends: 0 -->

</div>

<!-- index ends (don't remove) -->

</div>
</div>
